//
//  HomeListFromTableViewCell.m
//  Gxj
//
//  Created by 刘伟 on 2017/9/6.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "HomeListFromTableViewCell.h"

@interface HomeListFromTableViewCell ()
@property(nonatomic, strong) UILabel * paiHang;//排行-文字
@property(nonatomic, strong) UIImageView * image;
@property(nonatomic, strong) SDCycleScrollView *cycleScrollView4;//文字滚动条
@property(nonatomic, strong) UIImageView * viewHanhua;//文字滚动前的头像
@property (nonatomic,strong) UIButton *moreBtn;
@property (nonatomic,strong) UILabel *titleLab;

@end

@implementation HomeListFromTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self showListView];
    }
    return self;
}

- (void)showListView
{
    self.backgroundColor = [UIColor whiteColor];
    
    //榜单
    _image=[[UIImageView alloc] init];
    _image.image=[UIImage imageNamed:@"pai@2x"];
    [self addSubview:_image];
    
    /*  文字滚动  */
    _cycleScrollView4 = [[SDCycleScrollView alloc] init];
    _cycleScrollView4.placeholderImage=nil;
    _cycleScrollView4.scrollDirection = UICollectionViewScrollDirectionVertical;
    _cycleScrollView4.onlyDisplayText = YES;
    _cycleScrollView4.titleLabelBackgroundColor = [UIColor whiteColor];
    _cycleScrollView4.titleLabelTextColor = [UIColor colorWithHexString:@"#333333"];
    _cycleScrollView4.titleLabelTextFont=[UIFont systemFontOfSize:kWidthScale(12)];
    _cycleScrollView4.autoScrollTimeInterval = 3;
    
//    _cycleScrollView4.layer.shadowOffset = CGSizeMake(0, 0.3f);
//    _cycleScrollView4.layer.shadowOpacity = 0.2;
//    _cycleScrollView4.layer.shadowColor = [UIColor blackColor].CGColor;
    
    NSArray *titles = @[@"索大大七夕快乐 ",
                        @"disableScrollGesture可以设置禁止拖动",
                        @"感谢您的支持",
                        @"驚天動地只可惜天地亦無情",
                        @"在有生的瞬間能遇到你",
                        @"竟花光所有運氣",
                        @"到這日才發現",
                        @"曾呼吸過空氣",
                        
                        ];
    _cycleScrollView4.titlesGroup = [titles copy];
    [_cycleScrollView4 disableScrollGesture];
    [self addSubview:_cycleScrollView4];
    
    /*   文字滚动前的动画   */
    _viewHanhua=[[UIImageView alloc] init];
    _viewHanhua.image = [UIImage imageNamed:@"ren.png"];
    _viewHanhua.contentMode = UIViewContentModeScaleAspectFit;
    [self addSubview:_viewHanhua];
    
    [self showPaiHangBangBtn];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
}

- (void)showPaiHangBangBtn
{
    //榜单
    _image.sd_layout
    .topSpaceToView(self, kHeightScale(10))
    .leftSpaceToView(self, kWidthScale(15))
    .rightSpaceToView(self, kWidthScale(15))
    .heightIs(kHeightScale(75));
    //文字滚动前的动画图
    _viewHanhua.sd_layout.
    topSpaceToView(_image, kHeightScale(10))
    .leftSpaceToView(self, kWidthScale(15))
    .heightIs(kHeightScale(30))
    .widthIs(kWidthScale(24));
    //广告文字滚动
    _cycleScrollView4.sd_layout
    .topEqualToView(_viewHanhua)
    .leftSpaceToView(self.viewHanhua, kWidthScale(10))
    .rightSpaceToView(self, kWidthScale(15))
    .heightIs(kHeightScale(30));
    
    for (int i = 0; i < 4; i++) {
        self.discussBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        if (isiPhone6or6s) {
            self.discussBtn.frame = CGRectMake(15 + 93*i, 15, 65, 65);
        }
        if (isiPhone6plusor6splusoriPhone7oriPhone7plus) {
            self.discussBtn.frame = CGRectMake(15 + (103*i), 15, 70, 70);
        }
        self.discussBtn.tag = i+1000;
        [self.discussBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.discussBtn];
    }
}

- (void)clickBtn:(UIButton *)sender
{
    UIButton *btn = (UIButton *)sender;
    switch (btn.tag) {
        case 1000:
            [self.delegate clickListBtn:@"风暴"];
            NSLog(@"点击了风暴榜");
            break;
        case 1001:
            [self.delegate clickListBtn:@"讨论"];
            NSLog(@"点击了讨论榜");
            break;
        case 1002:
            [self.delegate clickListBtn:@"辩论"];
            NSLog(@"点击了辩论榜");
            break;
        case 1003:
            [self.delegate clickListBtn:@"等级"];
            NSLog(@"点击了风暴榜");
            break;
        default:
            break;
    }
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
